<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>最简单的双向绑定</title>
</head>
<body>
    <input type="text" id="a">
    <span id="b"></span>
    <script>
        var obj = {};
        var input = document.querySelector('#a');
        var span = document.querySelector('#b');

        input.addEventListener('keyup',(e)=>{
            span.innerHTML = e.target.value;
        })

        Object.defineProperty(obj,'text',{
            get:()=>{
                return "hello word";
            },
            set:(newValue)=>{
                console.log(newValue)
                input.value = newValue;
                span.innerHTML = newValue;
            }
        })
    </script>
</body>
</html>